﻿@model Eqwww.Domain.Models.SystemManage.ModuleButtonModel

@{
    ViewData["Title"] = "模块按钮管理";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";
}


<div id="eq-operate">
    <div class="mdui-appbar mdui-appbar-fixed mdui-color-white mdui-shadow-1">
        <div class="mdui-toolbar ">
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedButtons"></module-buttons>

            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedButtons" is-float="true"></module-buttons>

            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div class="mdui-appbar mdui-shadow-1 mdui-color-white" id="xd-appbar">
    <div class="mdui-toolbar ">

        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>
        <div class="mdui-toolbar-spacer"></div>


        <module-buttons class="mdui-btn-group" buttons="@ViewBag.InitialButtons"></module-buttons>


    </div>
</div>


<div class="mdui-container-fluid mdui-m-t-1 mdui-m-b-1">
    <div class="mdui-table-fluid">
        <table class="mdui-table" id="gridTable"></table>
        <div id="gridPager"></div>
    </div>
</div>


@section Scripts {
    <script>
        @{
            var ModuleButtonShowType = Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.SystemManage.ModuleButtonShowType));
        }
        var ModuleButtonShowType='@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(ModuleButtonShowType))';
        var moduleId = $.request("moduleId");
        $(function () {
            //$('.eq-list-table').eqTable();

            gridTable();
            $('#refreshBtn').bind('click', function () {
                //top.$.loadingLayer(true);
                window.location.reload();
            });
        });

        function gridTable() {
            var $gridList = $("#gridTable");
            $gridList.dataGrid({
                treeGrid: true,
                treeGridModel: "adjacency",
                ExpandColumn: "Code",
                url: '/SystemManage/ModuleButton/IndexGridJson?moduleId=' + moduleId,
                mtype: "GET",
                datatype: "json",
                colModel: [
                    { label: 'Id', name: 'Id', key: true, hidden: true },
                    { label: '@Html.DisplayNameFor(x=>Model.Name)', name: 'Name', width: 150, sortable:false },
                    { label: '编码', name: 'Code', width: 100, sortable: false },
                    {
                        label: '系统', name: 'IsSystem', width: 100, sortable:false, formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    {
                        label: '显示方式', name: 'ModuleButtonShowType', width: 100, formatter: function (cellValue) {
                            return $.GetEnumText(cellValue, ModuleButtonShowType);
                        }
                    },
                    { label: 'JS脚本', name: 'JsAction', width: 100, sortable: false },
                    { label: '连接地址', name: 'Url', width: 100, sortable: false },
                    { label: '图标', name: 'Icon', width: 100, sortable: false },
                    { label: '排序码', name: 'SortCode', width: 100,sortable:false },
                    {
                        label: '创建时间', name: 'CreateTime', width: 110, formatter: 'date', formatoptions: {
                            srcformat: 'Y-m-d', newformat: 'Y-m-d'
                        }
                    }

                ],
                height: getGridHeight()-32,
                shrinkToFit: true
            });

            $(window).resize(function () {
                //console.log(getGridHeight());
                $gridList.jqGrid('setGridHeight', getGridHeight() - 32);
            });

        }

        function btn_create() {

            $.modalOpen({
                id: 'formCreate',
                title: '新建按钮',
                url: '/SystemManage/ModuleButton/Create?moduleId=' + moduleId,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    var index = top.layer.getFrameIndex(window.name);
                    top.frames[iframeId].submitForm(index);
                }
            });
            return false;
        }

        function btn_clone() {
            var parentId = $('#gridTable').jqGridRowValue().Id;
            if (!parentId)
                parentId = '';
            $.modalOpen({
                id: 'formClone',
                title: '克隆按钮',
                url: '/SystemManage/ModuleButton/CloneButton?moduleId=' + moduleId + '&parentId=' + parentId,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    var index = top.layer.getFrameIndex(window.name);
                    top.frames[iframeId].submitForm(index);
                }
            });
            return false;
        }

        function btn_claims() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'ModuleButtonClaims',
                title: '按钮声明管理',
                url: '/SystemManage/ModuleButtonClaims?buttonId=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_edit() {
            var key = $('#gridTable').jqGridRowValue().Id;
            var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');

            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            if (isSystem == 'True') {
                $.modalMessage('系统按钮不允许修改！');
                return false;
            }
            $.modalOpen({
                id: 'formEditButton',
                title: '修改按钮',
                url: '/SystemManage/ModuleButton/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    var index = top.layer.getFrameIndex(window.name);
                    top.frames[iframeId].submitForm(index);
                }
            });
        }

        function btn_details() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemManage/ModuleButton/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_updateissystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定将本按钮提升为系统按钮吗？',
                url: '/SystemManage/ModuleButton/UpdateIsSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateisnotsystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.snackbar('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定将本按钮降级为一般按钮吗？',
                url: '/SystemManage/ModuleButton/UpdateIsNotSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_delete() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                $.modalMessage('未选中任何行！');
                return false;
            }
            var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');

            if (isSystem == 'True') {
                $.modalMessage('系统按钮不允许删除！');
                return false;
            }
            $.deleteForm({
                url: '/SystemManage/ModuleButton/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }
    </script>
}
